<?php
    class FeedController extends Controller
    {
        private $limit = 10;
        private $posts = array();
       
        public function init(){
            $this->posts = Post::model()->findAllByAttributes(
                array('status' => 'ENABLE'), 
                new CDbCriteria(array(
                    'order' => 'created ASC',
                    'limit' => $this->limit,
                ))
            );
            parent::init();
        } 

        
        public function actionIndex()
        {   
            Yii::import('ext.feed.*');
            // RSS 2.0 is the default type
            $feed = new EFeed();

            $feed->title= $this->siteName;
            $feed->description = $this->siteSlogan;

//            $feed->setImage($this->siteName, $this->baseUrl, "{$this->baseUrl}/files/img/logo.jpg");

            $feed->addChannelTag('language', 'en-us');
            $feed->addChannelTag('pubDate', date(DATE_RSS, time()));
            $feed->addChannelTag('link', $this->baseUrl);

            // * self reference
            $feed->addChannelTag('atom:link',$this->createAbsoluteUrl('/feed'));

            foreach($this->posts as $post){
                $item = $feed->createNewItem();

                $item->title = $post->title;
                $item->link = $post->url;
                $item->date = time();
                $item->description = $post->desc;

                $item->addTag('author', "{$post->manager->email} ({$post->manager->name})");
                $item->addTag('guid', $post->urlID, array('isPermaLink'=>'false'));
                $item->addTag('category', $post->cat->name);

                $feed->addItem($item);
            }

            $feed->generateFeed();
            Yii::app()->end();
        }
    }
